package cn.tedu.controller2;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

@RestController
@RequestMapping("user")
public class UserController {
    @RequestMapping("save")
    public String save(Integer id,String name,Integer age) throws Exception {
        System.out.println(id+name+age);
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3307/py-school-db?characterEncoding=utf8&amp;serverTimezone=Asia/Shanghai";
        Connection conn= DriverManager.getConnection(url,"root","123456");
        String sql="insert into user values(?,?,?)";
        PreparedStatement ps=conn.prepareStatement(sql);
        ps.setInt(1,id);
        ps.setString(2,name);
        ps.setInt(3,age);
        int rows = ps.executeUpdate();
        ps.close();
        conn.close();
        return id+name+age;
    }
    @RequestMapping("save2/{id}/{name}/{age}")
    public void save2(@PathVariable Integer id,
                      @PathVariable String name,
                      @PathVariable Integer age){
        System.out.println(id);
        System.out.println(name);
        System.out.println(age);
    }
}
